<template>
  <div >
    <div class="user-info">
      <div class="content">
        <input
          type="text"
          v-model="updateValue"
          class="update-input"
          ref="inputRef"
        />
        <span v-if="updateValue != ''"  @click="clearInput" class="iconfont icon-EP-guanbi1">✖</span>
      </div>
    </div>
    <div class="btn-over" >
      <div class="btn" @click="onClickOver">完成</div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      updateValue: '',
      updateState: {
        sign: 'updateSign',
        nickName: 'updateNickName',
        autoNym: 'updateAutoNym',
        phone: 'updatePhone'
      }
    }
  },
  created () {
    this.updateValue = this.$route.query.value
  },
  mounted () {
    this.$refs.inputRef.focus()
  },
  methods: {
    clearInput () {
      this.updateValue = ''
      this.$nextTick(() => {
        this.$refs.inputRef.focus()
      })
    },
    onClickOver () {
      if (this.updateValue === '') return false
      this.$store.commit(this.updateState[this.$route.query.type], this.updateValue)
      this.$router.push({ name: 'person' })
    }
  }
}
</script>

<style lang="less" scoped>
  .user-info {
    padding: 20px 10px;
    margin: 0 auto;
    background: #fff;
    .content {
      height: 48px;
      padding: 0 15px;
      border-radius: 5px;
      box-sizing: border-box;
      overflow: hidden;
      background: white;
      display: flex;
      justify-content: space-between;
      align-items: center;
      box-shadow: 2px 2px 8px 0px rgba(150,178,191,0.4);
      .update-input {
        width: 300px;
        height: 48px;
        border: none;
        outline: none;
        font-size: 14px;
      }
      span {
        margin-left: 15px;
        font-size: 10px;
        color: #999999;
      }
    }
  }
  .btn-over {
    // width: 100%;
    // margin: 20px auto;
    background: #fff;
    padding: 20px 20px;
    display: flex;
    justify-content: space-around;
      // box-shadow: 0px 0px 2px 0px rgba(150,178,191,0.2);

    .btn {
      width: 68px;
      height: 28px;
      line-height: 28px;
      font-size: 16px;
      background:linear-gradient(to right, rgb(255, 96, 52), rgb(238, 10, 36));
      text-align: center;
      color: #fff;
      border-radius: 5px;
    }
  }
</style>
